package com.dzjcloud.dzj.upms.biz.controller;

import com.dzjcloud.dzj.common.core.constant.CommonConstants;
import com.dzjcloud.dzj.common.core.utils.R;
import com.dzjcloud.dzj.upms.api.entity.User;
import com.dzjcloud.dzj.upms.api.form.UpdateUserPasswrodForm;
import com.dzjcloud.dzj.upms.api.form.UserRegisteredForm;
import com.dzjcloud.dzj.upms.biz.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <h3>dzj-cloud</h3>
 * <p>用户前端控制器</p>
 *
 * @author : DongZeJian
 * @date : 2021-06-01 11:09
 **/
@RestController
@Api(tags = "用户不需要权限前端控制器",value = "用户不需要权限前端控制器")
@RequestMapping("/user")
@Slf4j
@Validated
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @ApiOperation("修改密码")
    @PostMapping("/updatePasswrod")
    public R<Boolean> updateUserPasswrod(@RequestBody @Valid UpdateUserPasswrodForm updateUserPasswrodForm){
        return R.ok(userService.updateUserPasswrod(updateUserPasswrodForm));
    }

    @ApiOperation("实名认证")
    @PostMapping("/realNameAuth")
    public R<Boolean> realNameAuth(@ApiParam(value = "文件", required = true) @RequestParam("file")@NotNull(message = "文件不能为空") MultipartFile file,
                                   @ApiParam(value = "身份证的国徽面或人像面(front: 人像面、back: 国徽面)",required = true)@NotBlank(message = "身份证标识不能为空") String side){
        return R.ok(userService.realNameAuth(file,side));
    }

    @ApiOperation("更新头像")
    @PostMapping("/updateHead")
    public R<Boolean> updateHead(@ApiParam(value = "文件", required = true) @RequestParam("file")@NotNull(message = "文件不能为空") MultipartFile file){
        return R.ok(userService.updateHead(file));
    }

    @GetMapping("/list")
    @ApiOperation("用户列表")
    public R<List<User>> getList(){
        return R.ok(userService.list());
    }
}
